package com.zzptc.sky.baidudemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.fragments.SOSSecondFragment;
import com.zzptc.sky.baidudemo.utils.MyApplication;

import java.util.List;

/**
 * Created by Administrator on 2017/6/1.
 */

public class ContactsAdapter  extends RecyclerView.Adapter<ContactsAdapter.MyHolder>{

    private List<String> contactsList;
    private View itemView;

    public ContactsAdapter(List<String> list) {
        contactsList = list;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.contacts_items,parent,false);
        MyHolder myHolder = new MyHolder(itemView);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {

        final String number = contactsList.get(position);

        holder.tv_number.setText(number);

        holder.btn_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SOSSecondFragment.delList(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return contactsList.size();
    }

    public static class MyHolder extends RecyclerView.ViewHolder{

        private TextView tv_number;
        private Button btn_del;

        public MyHolder(View itemView) {
            super(itemView);

            tv_number = (TextView) itemView.findViewById(R.id.rv_items_tv);
            btn_del = (Button) itemView.findViewById(R.id.btn_del);
        }
    }
}
